Imports DotNetPm.Business.Questionnaire

Partial Class Modules_Questionnaires_Controls_logText
    Inherits System.Web.UI.UserControl
    Implements UserControls.ILogicUC

    Dim _question As Question

    Public Property Logic() As String Implements DotNetPm.Business.Questionnaire.UserControls.ILogicUC.Logic
        Get
            Dim sb As New StringBuilder
            sb.Append("6|")
            sb.Append(IIf(ddlAnswer.SelectedIndex = 2, ddlOperators.SelectedIndex, ""))
            sb.Append("|")
            sb.Append(txtChoices.Text)
            sb.Append("|")
            sb.Append(ddlAnswer.SelectedValue)
            Return sb.ToString
        End Get
        Set(ByVal value As String)
            If Not String.IsNullOrEmpty(value) Then
                Dim val As String() = value.Split("|")
                ddlAnswer.SelectedValue = val(3)
                If ddlAnswer.SelectedIndex = 2 Then
                    ddlOperators.SelectedIndex = val(1)
                End If
                txtChoices.Text = val(2)
            End If
            Dim conf As String() = Split(_question.Configuration, "||")
            rangeChoices.MaximumValue = CInt(conf(3))
            AdjustControls()
        End Set
    End Property

    Public Property Question() As Question Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Question
        Get
            Return _question
        End Get
        Set(ByVal value As Question)
            _question = value
        End Set
    End Property

    Public Sub Reset() Implements DotNetPm.Business.Questionnaire.UserControls.ILogicUC.Reset
        'ddlAnswer.SelectedIndex = -1
        'ddlOperators.SelectedIndex = -1
        'txtChoices.Text = String.Empty
    End Sub

    Private Sub AdjustControls()
        Select Case ddlAnswer.SelectedIndex
            Case 0  '-1 : No Condition
                reqChoices.Visible = False
                rangeChoices.Visible = False
                txtChoices.Visible = False
                lblOperator.Visible = False
                lblNote.Visible = False
                ddlOperators.Visible = False
            Case 1  ' 0 : Answer Contains
                reqChoices.Visible = True
                rangeChoices.Visible = False
                txtChoices.Visible = True
                txtChoices.Width = New Unit(480, UnitType.Pixel)
                lblOperator.Visible = True
                lblNote.Visible = True
                ddlOperators.Visible = False
            Case 2  ' 1 : Length of Answer
                reqChoices.Visible = True
                rangeChoices.Visible = True
                txtChoices.Visible = True
                txtChoices.Width = New Unit(120, UnitType.Pixel)
                lblOperator.Visible = False
                lblNote.Visible = False
                ddlOperators.Visible = True
        End Select
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        AdjustControls()
    End Sub
End Class
